package com.atguigu.flink.chapter05.Transform;

import com.atguigu.flink.chapter05.Source.WaterSensor;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * TODO
 *
 * @author cjp
 * @version 1.0
 * @date 2021/1/20 14:06
 */
public class Flink06_Shuffle {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);

        DataStreamSource<Integer> inputDS = env.fromElements(1, 2, 3, 4, 5, 6);

        //TODO shuffle
        DataStream<Integer> resultDS = inputDS.shuffle();

        inputDS.print("input");
        resultDS.print("shuffle");

        env.execute();
    }

}
/*
      shuffle原理：
        使用了 shuffle分区器：随机往 下游分区 发送
            random.nextInt(numberOfChannels)
                numberOfChannels = 下游的分区数 （并行度）
*/